package com.mfangsoft.zhuangjialong.integration.usermanage.controller;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.mfangsoft.zhuangjialong.common.model.Page;
import com.mfangsoft.zhuangjialong.common.model.ResponseMessage;
import com.mfangsoft.zhuangjialong.common.utils.SysConstant;
import com.mfangsoft.zhuangjialong.integration.usermanage.model.BaseUserManage;
import com.mfangsoft.zhuangjialong.integration.usermanage.model.BaseUserManagerModel;
import com.mfangsoft.zhuangjialong.integration.usermanage.model.CustomerUserManagerBasic;
import com.mfangsoft.zhuangjialong.integration.usermanage.model.CustomerUserManagerCommunicate;
import com.mfangsoft.zhuangjialong.integration.usermanage.model.SellerPointEntity;
import com.mfangsoft.zhuangjialong.integration.usermanage.model.UserCustomerReportEntity;
import com.mfangsoft.zhuangjialong.integration.usermanage.model.UserManagerTaskModel;
import com.mfangsoft.zhuangjialong.integration.usermanage.service.UserManageService;

@Controller
@RequestMapping("/app")
public class AppUserManagerController {

	
	@Autowired
	private UserManageService userManageServiceImpl; 
	
	/**
	 * 人员的任务查看
	 */
	@RequestMapping(value="/selectUerManagerTask",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Page<UserManagerTaskModel>> selectUerManagerTask(@RequestBody Page<UserManagerTaskModel> page) throws ParseException{
		
		ResponseMessage<Page<UserManagerTaskModel>> message = new ResponseMessage<Page<UserManagerTaskModel>>();
		try {
			Page<UserManagerTaskModel> userManagerTaskModelList = userManageServiceImpl.selectUerManagerTask(page);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(userManagerTaskModelList);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 人员的工作台当前任务
	 */
	@RequestMapping(value="/selectPresentUerManagerTask",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Page<UserManagerTaskModel>> selectPresentUerManagerTask(@RequestBody Page<UserManagerTaskModel> page) throws ParseException{
		
		ResponseMessage<Page<UserManagerTaskModel>> message = new ResponseMessage<Page<UserManagerTaskModel>>();
		try {
			Page<UserManagerTaskModel> userManagerTaskModelList = userManageServiceImpl.selectPresentUerManagerTask(page);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(userManagerTaskModelList);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 增加沟通记录
	 */
	@RequestMapping(value="/related/customer/addCommunicate",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<CustomerUserManagerCommunicate> relatedCustomerAddCommunicate(@RequestBody CustomerUserManagerCommunicate customerCommunicateEntity){
		ResponseMessage<CustomerUserManagerCommunicate> message = new ResponseMessage<CustomerUserManagerCommunicate>();
		try {
			userManageServiceImpl.addCommunicate(customerCommunicateEntity);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 回显沟通记录基本信息:根据导购id和消费者id查看是否有记录，有就修改，没有就增加
	 */
	@RequestMapping(value="/related/customer/selectCommunicate",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<CustomerUserManagerCommunicate> relatedCustomerSelectCommunicate(@RequestBody CustomerUserManagerCommunicate customerCommunicateEntity){
		ResponseMessage<CustomerUserManagerCommunicate> message = new ResponseMessage<CustomerUserManagerCommunicate>();
		try {
			CustomerUserManagerCommunicate customerUserManagerCommunicate = userManageServiceImpl.selectCommunicate(customerCommunicateEntity);
			if(customerUserManagerCommunicate == null)
				message.setCode("2");
			else
				message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(customerUserManagerCommunicate);
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 客户报备新增
	 */
	@RequestMapping(value="/related/addCustomerReport",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<UserCustomerReportEntity> addCustomerReport(@RequestBody UserCustomerReportEntity userCustomerReportEntity){
		ResponseMessage<UserCustomerReportEntity> message = new ResponseMessage<UserCustomerReportEntity>();
		try {
			userManageServiceImpl.addCustomerReport(userCustomerReportEntity);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 小程序中我的专属顾问
	 */
	@RequestMapping(value="/exclusiveConsultant",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<BaseUserManage> exclusiveConsultant(@RequestBody Map<String,Object> map){
		ResponseMessage<BaseUserManage> message = new ResponseMessage<BaseUserManage>();
		try {
			BaseUserManage result = userManageServiceImpl.selectExclusiveConsultant(map);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(result);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;	
	}
	
	/**
	 * 分享活动积分的增加
	 */
	@RequestMapping(value="/addIntegral",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<String> addIntegral(@RequestBody SellerPointEntity sellerPointEntity) {
		ResponseMessage<String> message = new ResponseMessage<String>();
		try {
		    
			userManageServiceImpl.addIntegral(sellerPointEntity);
	
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;	
	}
	
	/**
	 * 根据商户id和消费者id查看消费者和导购的沟通记录
	 */
	@RequestMapping(value="/selectRecordOfCommunication",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<List<CustomerUserManagerBasic>> selectRecordOfCommunication(@RequestBody Map<String,Object> map){
		ResponseMessage<List<CustomerUserManagerBasic>> message = new ResponseMessage<List<CustomerUserManagerBasic>>();
		try {
			List<CustomerUserManagerBasic> result = userManageServiceImpl.selectRecordOfCommunication(map);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(result);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;	
	}
	
	/**
	 * 导购的积分总数
	 */
	@RequestMapping(value="/selectUserManagerIntegral/{userManagerId}",method=RequestMethod.GET)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Integer> selectUserManagerIntegral(@PathVariable Long userManagerId){
		ResponseMessage<Integer> message = new ResponseMessage<Integer>();
		try {
			Integer userManagerIntegral = userManageServiceImpl.selectUserManagerIntegral(userManagerId);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(userManagerIntegral);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;	
	}
	
	/**
	 * 导购的积分管理列表
	 */
	@RequestMapping(value="/selectUserManagerIntegralManagement",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Page<SellerPointEntity>> selectUserManagerIntegralManagement(@RequestBody Page<SellerPointEntity> page){
		ResponseMessage<Page<SellerPointEntity>> message = new ResponseMessage<Page<SellerPointEntity>>();
		try {
			Page<SellerPointEntity> integrals = userManageServiceImpl.selectUserManagerIntegralManagement(page);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(integrals);
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 导购助手端的是否签到判断
	 */
	@RequestMapping(value="/selectUserManagerIsSing/{userManagerId}",method=RequestMethod.GET)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Object> selectUserManagerIsSing(@PathVariable Long userManagerId){
		ResponseMessage<Object> message = new ResponseMessage<Object>();
		try {
			Boolean isSing = userManageServiceImpl.selectUserManagerIsSing(userManagerId);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(isSing);
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 导购的签到增加积分
	 */
	@RequestMapping(value="/addUserManagerIsSing/{userManagerId}",method=RequestMethod.GET)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<String> addUserManagerIsSing(@PathVariable Long userManagerId){
		ResponseMessage<String> message = new ResponseMessage<String>();
		try {
			String sing = userManageServiceImpl.addUserManagerIsSing(userManagerId);
			message.setResult(sing);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 人员查询:根据人员id查询人员
	 * @param baseActivityInfo
	 * @return
	 */
	
	@RequestMapping(value="/selectUserManageOne/{id}",method=RequestMethod.GET)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<BaseUserManagerModel> selectUserManageOne(@PathVariable int id){
		ResponseMessage<BaseUserManagerModel> message = new ResponseMessage<BaseUserManagerModel>();
		try {
			BaseUserManagerModel bum =userManageServiceImpl.selectUserManageOne(id);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(bum);
		} catch (Exception e) {
			// TODO: handle exception
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			e.printStackTrace();
		}
		return message;
	}
}
